import { createRouter, createWebHashHistory } from "vue-router"


// const webHistory = createWebHistory()

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/login',
            name: 'login',
            component: () => import('./components/login.vue'),
        },
        {
            path: '/register',
            name: 'test',
            component: () => import('./components/register.vue')
        },
        {
            path: '/',
            name: 'index',
            component: () => import('./components/index.vue')
        },
        {
            path: '/goods',
            name: "goods",
            component: () => import("./components/goods/goods.vue"),
        },
        {
            path: "/goods/AddGoods",
            name: "AddGoods",
            component: () => import("./components/goods/AddGoods.vue")
        },
        {
            path: "/goods/EditGoods/:id",
            name: "EditGoods",
            component: () => import("./components/goods/EditGoods.vue")
        },
        {
            path: "/orderer",
            name: "orderer",
            component: () => import("./components/orderer/orderer.vue")
        },
        {
            path: "/orderer/orderDetail/:id",
            name: "orderDetail",
            component: () => import("./components/orderer/orderDetail.vue")
        },
        {
            path: "/orderer/deliverOrderList/:orderid",
            name: "deliverOrderList",
            component: () => import("./components/orderer/deliverOrderList.vue")
        }
    ]
})


//导航守卫
router.beforeEach((to, form, next) => {
    //访问下面路由直接放行
    if (to.path == "/" || to.path == "/login" || to.path == "/register") {
        next()
    } else {
        // 校验用户的，不受管理员影响
        const supplier_token = localStorage.getItem("supplier_token")
        // front的需要权限的url
        if (supplier_token == "" || supplier_token == null || supplier_token == '') {
            next("/login")
        } else {
            next()
        }
    }
}
)





export default router